function sum(){
	var items = document.getElementsByClassName("Text0");
	var timeSpan;
	var hoursSum = 0;
	var minutesSum = 0;
	var isWork = false;
	for(i=0;i<items.length;i++){		
		var hours = 0;
		var minutes = 0;
		var workDay = calcDay(items[i].children[0].innerHTML);
		isWork = isWorkDay(items[i].children[1].innerHTML);
		if (workDay < 6 && workDay > 0 && isWork) {
			timeSpan = getTime(items[i].children[1].innerHTML, items[i].children[2].innerHTML, items[i]);
			hours = timeSpan.getHours() - 9;
			minutes = timeSpan.getMinutes();
			hoursSum += hours;
			minutesSum += minutes;
			items[i].innerHTML += "<td>"+hours + ":" + minutes+"</td>";
		}

		if (workDay == 1) {
			var hoursFromMinutes = parseInt(minutesSum / 60);
			var minutesLeft = minutesSum % 60;
			hoursSum += hoursFromMinutes;
			if (hoursSum < 40) {
				items[i].innerHTML += "<td style='background-color:Red'>" + hoursSum + ":" + minutesLeft + "</td>";
			} else {
				items[i].innerHTML += "<td>" + hoursSum + ":" + minutesLeft + "</td>";
			}
			hoursSum = 0;
			minutesSum = 0;
		} else if (isWork) {
			items[i].innerHTML += "<td></td>";
		}
	}
}

function getTime(startTime, endTime, item){
	var start = new Date(startTime);
	if (start.getHours() < 8) {
		start.setHours(10);
		start.setMinutes(0, 0, 0);
		item.children[1].innerHTML += "<br /><p>starts at 10 am</p>"
	}
	var end = new Date(endTime);
	var span = end - start;
	return new Date(span);	
}

function calcDay(workDate){
	var date = new Date(workDate);
	var day = date.getDay();
	console.log(date);
	console.log(day);
	return day;
}

function isWorkDay(startTime) {
	if (startTime == "&nbsp;") {
		return false;
	} else {
		return true;
	}
}

function addColumns() {
	var table = document.getElementById("myLogList_dgLogList");
	table.children[0].children[0].innerHTML += "<td>Amount</td><td>Total</td>";
}

addColumns();
sum();